[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 getc()                  Read a Character from a Stream (Macro)

 #include   <stdio.h>

 int        getc(stream);
 FILE       *stream;                     Pointer to file stream

    getc() reads the next character from the input 'stream'.  If there is
    an associated file pointer, it is incremented to point to the next
    character.

       Returns:     If successful, getc() returns the character read.
                    getc() returns the value of EOF if there is an error
                    or end-of-file has been reached.

         Notes:     Use ferror() or feof() to determine whether an error
                    or an end-of-file occurred.

                    fgetc() is similar to getc(), but getc() is a macro,
                    while fgetc() is a function.

   -------------------------------- Example ---------------------------------

    The following statements open and print a file.

           #include <stdio.h>

           FILE *in;
           int next_ch;

           main()
           {
                if ((in = fopen("alph.dat","r+")) != NULL) {
                   while(!feof(in))  {
                      next_ch = getc(in);
                      printf("%c ",next_ch);
                   }
                   fclose(in);
                }
           }



See Also: fgetc() getchar() getch() getche()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson